package com.scqkxx.gamebox.activity.home.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.FindCallback;
import com.avos.avoscloud.SaveCallback;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.scqkxx.gamebox.R;
import com.scqkxx.gamebox.activity.game.adapter.GameGridAdapter;
import com.scqkzqtz.base.library.utils.ToastUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2018/8/15. 09点37分
 * name: 唐师
 * 用途 ： 游戏页面的适配器
 */

public class NavSpaceAdapter extends BaseQuickAdapter<AVObject, BaseViewHolder> {
    private GameGridAdapter mGameGridAllAdapter;

    public NavSpaceAdapter(int layoutResId, List<AVObject> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, AVObject item) {
        helper.setText(R.id.tv_nav_space_name, "#  " + item.getString("name"));

        List<AVObject> list = new ArrayList<>();
        NavPositionAdapter navPositionAdapter = new NavPositionAdapter(R.layout.item_nav_team, list);
        RecyclerView recyclerView = helper.convertView.findViewById(R.id.rv_position_list);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
        recyclerView.setAdapter(navPositionAdapter);

        helper.convertView.findViewById(R.id.tv_nav_space_name).setOnClickListener(view -> {
            recyclerView.setVisibility(recyclerView.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
        });

        AVQuery<AVObject> teamQuery = AVQuery.getQuery("Position");
        teamQuery.whereEqualTo("spaceId", Integer.parseInt(item.getObjectId()));
        teamQuery.findInBackground(new FindCallback<AVObject>() {
            @Override
            public void done(List<AVObject> avObjects, AVException avException) {
                Log.i("Position",avObjects+"");
                if (avException == null) {
                    list.clear();
                    list.addAll(avObjects);
                    navPositionAdapter.notifyDataSetChanged();
                }

                if(avObjects == null || avObjects.size() <= 0){
                    TextView textView = helper.convertView.findViewById(R.id.tv_nav_space_name);
                    textView.setTextColor(Color.parseColor("#d8d8d8"));
                }
            }
        });


    }
}
